﻿
// ================================================================================================
// -*- C++ -*-
// File: fnt.hpp
// Author: Guilherme R. Lampert
// Created on: 18/02/16
// Brief: FNT file parsing and the font/char-set structures.
//
// This source code is released under the MIT license.
// See the accompanying LICENSE file for details.
// ================================================================================================

#ifndef FNT_HPP
#define FNT_HPP

#include <d3d9.h>
#include <unordered_map>

//
// Output Font structures:
//

struct FontChar
{
    // Position inside the glyph bitmap.
    std::uint16_t x;
    std::uint16_t y;
	std::uint16_t width;
	std::uint16_t height;
	BYTE page;
};

struct FontCharSet
{
	const FontChar* GetChar(DWORD n) const;

	LPDIRECT3DTEXTURE9 TextureBitMap;		// 由外部创建纹理 外部销毁
    int bitmapWidth;		// 创建纹理时赋值
    int bitmapHeight;		// 创建纹理时赋值

    // The number of pixels from the absolute top of the line to the base of the characters.
    // See: http://www.angelcode.com/products/bmfont/doc/file_format.html
    int charBaseHeight;

    // Assumed fixed width & height.
//	int charWidth;
//	int charHeight;
    int charCount;
	std::unordered_map<DWORD, FontChar> map_FontChar;
};

// Simple text FNT parser that reads only the fields we care about.
// Calls ::error() if something goes wrong.
void parseTextFntFile(const std::wstring& filename, FontCharSet& charSetOut);

#endif // FNT_HPP
